package Datalog
import DatalogAtom.createAtom

object Test {
  def atomArityTest1(): Unit = {
    val atoms = List(
      createAtom("foo", "A"),
      createAtom("bar", "y", "z"),
      createAtom("baz", "C", "D"))
    val resolution = createAtom("foo", "A", "D")
    val rule = new DatalogRule(atoms, resolution)

    val isDLRule = rule.isDLRule
    println(isDLRule)
    assert(true == isDLRule)
  }

  def atomArityTest11(): Unit = {
    val atoms = List(
      createAtom("blub", "Y", "C"),
      createAtom("blob", "C", "D"))
    val resolution = createAtom("bla", "A", "D")
    val rule = new DatalogRule(atoms, resolution)

    val isDLRule = rule.isDLRule
    println(isDLRule)
    assert(true == isDLRule, " atomArityTest11")
  }

  def atomArityTest2(): Unit = {
    val atoms = List(
      createAtom("foo", "A"),
      createAtom("bar", "B", "C"),
      createAtom("baz", "C", "D"))
    val resolution = createAtom("foo")
    val rule = new DatalogRule(atoms, resolution)

    val isDLRule = rule.isDLRule
    println(isDLRule)
    assert(false == isDLRule, "atomArityTest2")
  }

  def VariableTest1(): Unit = {
    val atoms = List(
      createAtom("foo", "x", "y"),
      createAtom("bar", "y", "z"),
      createAtom("baz", "z", "w"))
    val resolution = createAtom("foo", "x", "w")
    val rule = new DatalogRule(atoms, resolution)

    val isDLRule = rule.isDLRule
    println(isDLRule)
    assert(true == isDLRule, "VariableTest1")
  }

  def VariableTest2(): Unit = {
    val atoms = List(
      createAtom("foo", "x", "y"),
      createAtom("bar", "y", "z"))
    val resolution = createAtom("foo", "x", "w")
    val rule = new DatalogRule(atoms, resolution)

    val isDLRule = rule.isDLRule
    println(isDLRule)
    assert(true == isDLRule, "VariableTest2")
  }

  def isDlRule(): Unit = {
    val atoms = List(
      createAtom("P", "z"),
      createAtom("R", "x", "y"),
      createAtom("Q", "F", "x"))
    println(atoms)
    val resolution = createAtom("Q", "x", "z")
    val rule = new DatalogRule(atoms, resolution)

    assert(true == rule.isDLRule(), "isDlRule fails")
  }

  def notIsDlRule(): Unit = {
    val atoms = List(
      createAtom("R", "x", "y"),
      createAtom("Q", "x", "z"),
      createAtom("P", "z", "y"))
    val resolution = createAtom("R", "x")
    val rule = new DatalogRule(atoms, resolution)

    assert(false == rule.isDLRule(), "notIsDlRule")

  }

  def main(args: Array[String]): Unit = {
    val nul = new DatalogRule(null, null)

    val atoms = List(
      createAtom("bla", "A", "B"),
      createAtom("bla", "x", "y"),
      createAtom("blub", "y", "z"),
      createAtom("blob", "z", "w"))
    val resolution = createAtom("bla", "x", "w")
    val rule = new DatalogRule(atoms, resolution)

    val startset = nul.makePaths(atoms).toSet

    println(nul.combine(startset, startset))
    assert(true == rule.isDLRule())

    println("atomArityTest1")
    atomArityTest1();
    println("atomArityTest11")
    atomArityTest11();
    println("AtomarityTest2")
    atomArityTest2();
    println("VariableTest1")
    VariableTest1();
    println("VariableTest2")
    VariableTest2();
    println("isDLRule")
    isDlRule()
    println("notIsDLRule")
    notIsDlRule()
  }

}